using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ACME.Northwind.DataTransfer;
using System.Linq.Expressions;
using ACME.Northwind.Service.Interfaces;

namespace ACME.Northwind.WCFProxy
{
	/// <summary>
	/// The service implementation for OrderDetail object
	/// </summary>
	public partial class OrderDetailService : IOrderDetailService
	{
		#region IOrderDetailService Members

		/// <summary>
		/// Run a selection by the primary key
		/// </summary>
		public OrderDetailDTO SelectByPrimaryKey(int orderid, int productid)
		{
			return DataService.Instance.GetOrderDetail(orderid, productid);
		}

		/// <summary>
		/// Run the persist for a list
		/// </summary>
		public bool Persist(List<OrderDetailDTO> list)
		{
			bool retval = true;
			foreach (OrderDetailDTO orderdetail in list)
			{
				retval &= this.Persist(orderdetail);
			}
			return retval;
		}

		/// <summary>
		/// Run the persist for an object
		/// </summary>
		public bool Persist(OrderDetailDTO dto)
		{
			return (DataService.Instance.PersistOrderDetail(dto) != null);
		}

		/// <summary>
		/// Run a selection using LINQ
		/// </summary>
		public List<OrderDetailDTO> RunSelect(string linq)
		{
			List<OrderDetailDTO> retVal = new List<OrderDetailDTO>();
			retVal.AddRange(DataService.Instance.GetOrderDetailListByLINQ(linq));
			return retVal;
		}

		/// <summary>
		/// Run a paginated selection using LINQ
		/// </summary>
		public PagedQueryResults<OrderDetailDTO> RunSelect(int pageIndex, int pageSize, bool ascending, string sortColumn, string linq)
		{
			return DataService.Instance.GetOrderDetailListPaged(pageIndex, pageSize, ascending, sortColumn, linq);
		}

		/// <summary>
		/// Run a selection for all objects
		/// </summary>
		public List<OrderDetailDTO> RunSelect()
		{
			List<OrderDetailDTO> retVal = new List<OrderDetailDTO>();
			DataServiceClient ds = DataService.Instance;
			retVal.AddRange(ds.GetOrderDetailList());
			return retVal;
		}

		/// <summary>
		/// Return the related Order item
		/// </summary>
		public OrderDTO GetOrderItem(OrderDetailDTO item)
		{
			OrderDTO retval = new OrderDTO();
			DataServiceClient ds = DataService.Instance;
			retval = ds.GetOrder(item.OrderId);
			return retval;
		}

		/// <summary>
		/// Return the related Product item
		/// </summary>
		public ProductDTO GetProductItem(OrderDetailDTO item)
		{
			ProductDTO retval = new ProductDTO();
			DataServiceClient ds = DataService.Instance;
			retval = ds.GetProduct(item.ProductId);
			return retval;
		}

		/// <summary>
		/// Delete the specified item
		/// </summary>
		public bool Delete(OrderDetailDTO item)
		{
			DataServiceClient ds = DataService.Instance;
			return ds.DeleteOrderDetail(item);
		}

		#endregion
	}
}
